package sjtu.ist.warehouse4ws.tool.file;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Change2UTF {
	
	

	public static void change(String filepath )throws IOException{
		
		    String src="";
		    String dst="";
	        BufferedReader br = null;
	        FileReader fr = null;
	        try {
	            fr = new FileReader(filepath);
	            br = new BufferedReader(fr);

	            String readin = br.readLine();
                
	            while (readin != null) {
	                src = src + readin + "\n";
	                readin = br.readLine();
	            }
	            dst= new String(src.getBytes(), "utf-8");
	            br.close();
	            fr.close();
	        } catch (IOException e) {
	            try {
	                if (br != null) {
	                    br.close();
	                }
	                if (fr != null) {
	                    fr.close();
	                }
	            } catch (IOException ex) {
	                // ignore
	            }
	            // re-throw exception
	            throw e;
	        }
	        BufferedWriter bw;
	        FileWriter fw;

	        try {
	            fw = new FileWriter(filepath);
	            bw = new BufferedWriter(fw);
	            bw.write(dst);
	            bw.close();
	            fw.close();
	        } catch (IOException e) {
	            e.printStackTrace();
	            
	        }
           
	}
	

}
